package de.szut.entity;

import com.j256.ormlite.field.DataType;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import de.szut.impl.ModifierDaoImpl;
import de.szut.util.ModifierType;

import java.io.Serializable;

/**
 * TODO
 * Created by dzebcuks on 19.08.13.
 */
@DatabaseTable(daoClass = ModifierDaoImpl.class)
public class Modifier implements Serializable {

    @DatabaseField(generatedId = true)
    private int id;

    @DatabaseField
    private ModifierType type;

    /**
     * Value of changed modifier
     * The modifierValue has to be one of the following possibilities:
     * - percent (provide %-symbol)
     * - absolute (provide either + or -)
     */
    @DatabaseField(foreign = true, foreignAutoRefresh = true, foreignAutoCreate = true)
    private ModifierValue modifierValue;

    /**
     * If the modifier is somehow connected to another modifier this is the way to set it.
     * Otherwise it should be null.
     */
    @DatabaseField(dataType = DataType.SERIALIZABLE)
    private Modifier connectedModifier;

    @Override
    public boolean equals(Object o) {
        boolean equals = false;
        if (o instanceof Modifier) {
            if (this.type.equals(((Modifier) o).getType()) && this.modifierValue.equals(((Modifier) o)
                    .getModifierValue())) {
                equals = true;
            }
        }
        return equals;
    }

    public int getId() {
        return id;
    }

    public ModifierValue getModifierValue() {
        return modifierValue;
    }

    public void setModifierValue(ModifierValue modifierValue) {
        this.modifierValue = modifierValue;
    }

    public void setId(int id) {
        this.id = id;
    }

    public ModifierType getType() {
        return type;
    }

    public void setType(ModifierType type) {
        this.type = type;
    }

    public Modifier getConnectedModifier() {
        return connectedModifier;
    }

    public void setConnectedModifier(Modifier connectedModifier) {
        this.connectedModifier = connectedModifier;
    }
}
